#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api01_connections.py 
@version:
@time: 2022/05/10 
"""
import json

from TapClientCore.T02_tm_api.v1_api.v1_api_base import *


class V1Connections(V1ApiBase):

    def __init__(self, change=''):
        super(V1Connections, self).__init__(change)
        self.url_connections = api_joint(self.server, 'Connections')

    # 查询
    def get_connections(self):
        response = self.tapclient(
            self.get,
            self.url_connections
        )
        return response

    # 查询 by filter
    def get_connections_by_filter(self, _filter):
        f = json.dumps(_filter)
        response = self.tapclient(
            self.get,
            self.url_connections
            + self.filter(f)
        )
        return response

    # 查询 by id
    def get_connections_by_id(self, connections_id):
        response = self.tapclient(
            self.get,
            api_joint(
                self.url_connections,
                connections_id
            )
        )
        return response

    # 创建
    def post_connections(self, payload):
        response = self.tapclient(
            self.post,
            self.url_connections,
            json=payload
        )
        return response

    # 复制
    def post_copy_connections(self, conneciont_id, payload):
        response = self.tapclient(
            self.post,
            api_joint(
                self.url_connections,
                conneciont_id,
                'copy'
            ),
            json=payload
        )
        return response

    # 删除 by id
    def delete_connections_by_id(self, connections_id):
        response = self.tapclient(
            self.delete,
            api_joint(
                self.url_connections,
                connections_id
            )
        )
        return response

    # 修改
    def patch_connections_by_id(self, connections_id, payload):
        response = self.tapclient(
            self.patch,
            api_joint(
                self.url_connections,
                connections_id
            ),
            json=payload
        )
        return response
